
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>路由懒加载 · introduce</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="icons.html" />
    
    
    <link rel="prev" href="cors.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    Vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="jsdoc.html">
            
                <a href="jsdoc.html">
            
                    
                    Jsdoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    Webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="router.html">
            
                <a href="router.html">
            
                    
                    路由和侧边栏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="cors.html">
            
                <a href="cors.html">
            
                    
                    跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8" data-path="router-lazyload.html">
            
                <a href="router-lazyload.html">
            
                    
                    路由懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="icons.html">
            
                <a href="icons.html">
            
                    
                    图标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="i18n.html">
            
                <a href="i18n.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="eslint.html">
            
                <a href="eslint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="permission.html">
            
                <a href="permission.html">
            
                    
                    权限验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="style.html">
            
                <a href="style.html">
            
                    
                    样式
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >路由懒加载</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;">&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;</h1>
<p>&#x5F53;&#x6253;&#x5305;&#x6784;&#x5EFA;&#x5E94;&#x7528;&#x65F6;&#xFF0C;Javascript &#x5305;&#x4F1A;&#x53D8;&#x5F97;&#x975E;&#x5E38;&#x5927;&#xFF0C;&#x5F71;&#x54CD;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x901F;&#x5EA6;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x80FD;&#x628A;&#x4E0D;&#x540C;&#x8DEF;&#x7531;&#x5BF9;&#x5E94;&#x7684;&#x7EC4;&#x4EF6;&#x5206;&#x5272;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x7136;&#x540E;&#x5F53;&#x8DEF;&#x7531;&#x88AB;&#x8BBF;&#x95EE;&#x7684;&#x65F6;&#x5019;&#x624D;&#x52A0;&#x8F7D;&#x5BF9;&#x5E94;&#x7EC4;&#x4EF6;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x66F4;&#x52A0;&#x9AD8;&#x6548;&#x4E86;&#x3002;</p>
<p>&#x7ED3;&#x5408; Vue &#x7684;<a href="https://cn.vuejs.org/v2/guide/components.html#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" target="_blank">&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a>&#x548C; Webpack &#x7684;<a href="https://www.webpackjs.com/guides/code-splitting/" target="_blank">&#x4EE3;&#x7801;&#x5206;&#x5272;&#x529F;&#x80FD;</a>&#xFF0C;&#x8F7B;&#x677E;&#x5B9E;&#x73B0;&#x8DEF;&#x7531;&#x7EC4;&#x4EF6;&#x7684;&#x61D2;&#x52A0;&#x8F7D;&#x3002;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">const</span> <span class="token function-variable function">Foo</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;./Foo.vue&apos;</span><span class="token punctuation">)</span>
</code></pre>
<p><strong>&#x5F53;&#x4F60;&#x89C9;&#x5F97;&#x4F60;&#x7684;&#x9875;&#x9762;&#x70ED;&#x66F4;&#x65B0;&#x901F;&#x5EA6;&#x6162;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x624D;&#x9700;&#x8981;&#x5F80;&#x4E0B;&#x770B; &#x2193;</strong></p>
<h2 id="&#x533A;&#x5206;&#x5F00;&#x53D1;&#x4E0E;&#x751F;&#x4EA7;&#x73AF;&#x5883;-&#x8BE5;&#x65B9;&#x6848;&#x5DF2;&#x6DD8;&#x6C70;">&#x533A;&#x5206;&#x5F00;&#x53D1;&#x4E0E;&#x751F;&#x4EA7;&#x73AF;&#x5883; [&#x8BE5;&#x65B9;&#x6848;&#x5DF2;&#x6DD8;&#x6C70;]</h2>
<p>&#x5F53;&#x4F60;&#x7684;&#x9879;&#x76EE;&#x9875;&#x9762;&#x8D8A;&#x6765;&#x8D8A;&#x591A;&#x4E4B;&#x540E;&#xFF0C;&#x5728;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x4E4B;&#x4E2D;&#x4F7F;&#x7528; <code>lazy-loading</code> &#x4F1A;&#x53D8;&#x5F97;&#x4E0D;&#x592A;&#x5408;&#x9002;&#xFF0C;&#x6BCF;&#x6B21;&#x66F4;&#x6539;&#x4EE3;&#x7801;&#x89E6;&#x53D1;&#x70ED;&#x66F4;&#x65B0;&#x90FD;&#x4F1A;&#x53D8;&#x5F97;&#x975E;&#x5E38;&#x7684;&#x6162;&#x3002;&#x6240;&#x4EE5;&#x5EFA;&#x8BAE;&#x53EA;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E4B;&#x4E2D;&#x4F7F;&#x7528;&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;&#x529F;&#x80FD;&#x3002;</p>
<p><strong>&#x5F00;&#x53D1;&#x73AF;&#x5883;&#xFF1A;</strong></p>
<pre class="language-"><code class="lang-js">module<span class="token punctuation">.</span><span class="token function-variable function">exports</span> <span class="token operator">=</span> <span class="token parameter">file</span> <span class="token operator">=&gt;</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&apos;@/views/&apos;</span> <span class="token operator">+</span> file <span class="token operator">+</span> <span class="token string">&apos;.vue&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>default <span class="token comment">// vue-loader at least v13.0.0+</span>
</code></pre>
<p><strong>&#x8FD9;&#x91CC;&#x6CE8;&#x610F;&#x4E00;&#x4E0B;&#x8BE5;&#x5199;&#x6CD5;&#x53EA;&#x652F;&#x6301; <code>vue-loader at least v13.0.0+</code>&#x7406;&#x7531; <a href="https://github.com/PanJiaChen/vue-element-admin/issues/231" target="_blank">vue-element-admin/issues/231</a></strong></p>
<p><strong>&#x751F;&#x4EA7;&#x73AF;&#x5883;&#xFF1A;</strong></p>
<pre class="language-"><code class="lang-js">module<span class="token punctuation">.</span><span class="token function-variable function">exports</span> <span class="token operator">=</span> <span class="token parameter">file</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;@/views/&apos;</span> <span class="token operator">+</span> file <span class="token operator">+</span> <span class="token string">&apos;.vue&apos;</span><span class="token punctuation">)</span>
</code></pre>
<h2 id="&#x6DD8;&#x6C70;&#x539F;&#x56E0;">&#x6DD8;&#x6C70;&#x539F;&#x56E0;</h2>
<p>&#x5F53;&#x7136;&#x8FD9;&#x6837;&#x5199;&#x4F1A;&#x6709;&#x4E00;&#x4E9B;&#x526F;&#x4F5C;&#x7528;&#x3002;&#x7531;&#x4E8E;</p>
<blockquote>
<p>Every module that could potentially be requested on an import() call is included. For example, import(./locale/${language}.json) will cause every .json file in the ./locale directory to be bundled into the new chunk. At run time, when the variable language has been computed, any file like english.json or german.json will be available for consumption.</p>
</blockquote>
<p><code>@/views/&#x4E0B;&#x7684; .vue</code> &#x6587;&#x4EF6;&#x90FD;&#x4F1A;&#x88AB;&#x6253;&#x5305;&#x3002;&#x4E0D;&#x7BA1;&#x4F60;&#x662F;&#x5426;&#x88AB;&#x4F9D;&#x8D56;&#x3002;&#x6240;&#x4EE5;&#x8FD9;&#x6837;&#x5C31;&#x4EA7;&#x751F;&#x4E86;&#x4E00;&#x4E2A;&#x526F;&#x4F5C;&#x7528;&#xFF0C;&#x5C31;&#x662F;&#x4F1A;&#x591A;&#x6253;&#x5305;&#x4E00;&#x4E9B;&#x53EF;&#x80FD;&#x6C38;&#x8FDC;&#x90FD;&#x7528;&#x4E0D;&#x5230; js &#x4EE3;&#x7801;&#x3002;&#x5F53;&#x7136;&#x8FD9;&#x53EA;&#x4F1A;&#x589E;&#x52A0; dist &#x6587;&#x4EF6;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x4F46;&#x4E0D;&#x4F1A;&#x5BF9;&#x7EBF;&#x4E0A;&#x4EE3;&#x7801;&#x4EA7;&#x751F;&#x4EFB;&#x4F55;&#x7684;&#x526F;&#x4F5C;&#x7528;&#x3002;<a href="https://github.com/PanJiaChen/vue-element-admin/issues/292" target="_blank">&#x76F8;&#x5173; issue</a></p>
<p>TIP</p>
<p>&#x7528;&#x6237;&#x81EA;&#x5DF1;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x4E1A;&#x52A1;&#x60C5;&#x51B5;&#x6765;&#x8861;&#x91CF;&#x4E00;&#x4E0B;&#x662F;&#x5426;&#x91C7;&#x7528;&#x672C;&#x65B9;&#x6848;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x7684;&#x9879;&#x76EE;&#x9875;&#x9762;&#x4E0D;&#x8D85;&#x8FC7;&#x51E0;&#x5341;&#x4E2A;&#xFF0C;&#x672C;&#x5730;&#x5F00;&#x53D1;&#x70ED;&#x66F4;&#x65B0;&#x901F;&#x5EA6;&#x4F60;&#x8FD8;&#x80FD;&#x63A5;&#x53D7;&#x7684;&#x8BDD;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x6240;&#x6709;&#x73AF;&#x5883;&#x4E0B;&#x90FD;&#x662F;&#x7528;&#x61D2;&#x52A0;&#x8F7D;&#x907F;&#x514D;&#x6B64;&#x526F;&#x4F5C;&#x7528;&#x3002;</p>
<h2 id="&#x65B0;&#x65B9;&#x6848;">&#x65B0;&#x65B9;&#x6848;</h2>
<p>&#x4F7F;&#x7528;<code>babel</code> &#x7684; <code>plugins</code> <a href="https://github.com/airbnb/babel-plugin-dynamic-import-node" target="_blank">babel-plugin-dynamic-import-node</a>&#x3002;&#x5B83;&#x53EA;&#x505A;&#x4E00;&#x4EF6;&#x4E8B;&#x5C31;&#x662F;&#x5C06;&#x6240;&#x6709;&#x7684;<code>import()</code>&#x8F6C;&#x5316;&#x4E3A;<code>require()</code>&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x53EF;&#x4EE5;&#x7528;&#x8FD9;&#x4E2A;&#x63D2;&#x4EF6;&#x5C06;&#x6240;&#x6709;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x90FD;&#x7528;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x5F0F;&#x5F15;&#x5165;&#xFF0C;&#x5E76;&#x7ED3;&#x5408; <a href="https://babeljs.io/docs/usage/babelrc/#env-option" target="_blank">BABEL_ENV</a> &#x8FD9;&#x4E2A;<code>babel</code>&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF0C;&#x8BA9;&#x5B83;&#x53EA;&#x4F5C;&#x7528;&#x4E8E;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x4E0B;&#xFF0C;&#x5728;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x4E2D;&#x5C06;&#x6240;&#x6709;<code>import()</code>&#x8F6C;&#x5316;&#x4E3A;<code>require()</code>&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x6848;&#x89E3;&#x51B3;&#x4E86;&#x4E4B;&#x524D;&#x91CD;&#x590D;&#x6253;&#x5305;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x540C;&#x65F6;&#x5BF9;&#x4EE3;&#x7801;&#x7684;&#x4FB5;&#x5165;&#x6027;&#x4E5F;&#x5F88;&#x5C0F;&#xFF0C;&#x4F60;&#x5E73;&#x65F6;&#x5199;&#x8DEF;&#x7531;&#x7684;&#x65F6;&#x5019;&#x53EA;&#x9700;&#x8981;&#x6309;&#x7167;&#x5B98;&#x65B9;<a href="https://router.vuejs.org/zh/guide/advanced/lazy-loading.html" target="_blank">&#x6587;&#x6863;</a>&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;&#x7684;&#x65B9;&#x5F0F;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x5176;&#x5B83;&#x7684;&#x90FD;&#x4EA4;&#x7ED9;<code>babel</code>&#x6765;&#x5904;&#x7406;&#xFF0C;&#x5F53;&#x4F60;&#x4E0D;&#x60F3;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6848;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E5F;&#x53EA;&#x8981;&#x5C06;&#x5B83;&#x4ECE;<code>babel</code> &#x7684; <code>plugins</code>&#x4E2D;&#x79FB;&#x9664;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p><strong>&#x5177;&#x4F53;&#x4EE3;&#x7801;&#xFF1A;</strong></p>
<p>&#x9996;&#x5148;&#x5728;<code>package.json</code>&#x4E2D;&#x589E;&#x52A0;<code>BABEL_ENV</code></p>
<pre class="language-"><code class="lang-json"><span class="token property">&quot;dev&quot;</span><span class="token operator">:</span> <span class="token string">&quot;cross-env BABEL_ENV=development webpack-dev-server --inline --progress --config build/webpack.dev.conf.js&quot;</span>
</code></pre>
<p>&#x63A5;&#x7740;&#x5728;<code>.babelrc</code>&#x53EA;&#x80FD;&#x52A0;&#x5165;<code>babel-plugin-dynamic-import-node</code>&#x8FD9;&#x4E2A;<code>plugins</code>&#xFF0C;&#x5E76;&#x8BA9;&#x5B83;&#x53EA;&#x6709;&#x5728;<code>development</code>&#x6A21;&#x5F0F;&#x4E2D;&#x624D;&#x751F;&#x6548;&#x3002;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;env&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;development&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;plugins&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;dynamic-import-node&quot;</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E4B;&#x540E;&#x5C31;&#x5927;&#x529F;&#x544A;&#x6210;&#x4E86;&#xFF0C;&#x8DEF;&#x7531;&#x53EA;&#x8981;&#x50CF;&#x5E73;&#x65F6;&#x4E00;&#x6837;&#x5199;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<pre class="language-"><code class="lang-js"> <span class="token punctuation">{</span> path<span class="token operator">:</span> <span class="token string">&apos;/login&apos;</span><span class="token punctuation">,</span> <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;@/views/login/index&apos;</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
</code></pre>
<p><a href="https://github.com/PanJiaChen/vue-element-admin/pull/727" target="_blank">&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x6539;&#x52A8;</a></p>
<h2 id="vue-cli3-&#x8BE5;&#x65B9;&#x6848;&#x5DF2;&#x6DD8;&#x6C70;">vue-cli@3 [&#x8BE5;&#x65B9;&#x6848;&#x5DF2;&#x6DD8;&#x6C70;]</h2>
<p><code>vue-element-admin@4</code> &#x5728;&#x65B0;&#x7248;&#x672C;&#x4E2D;&#x5DF2;&#x4FEE;&#x6539;&#x4E3A;&#x57FA;&#x4E8E; <code>vue-cli</code>&#x6765;&#x8FDB;&#x884C;&#x6784;&#x5EFA;&#x3002;&#x6240;&#x4EE5;&#x5728;&#x65B0;&#x7248;&#x672C;&#x4E2D;&#x4F60;&#x53EA;&#x8981;&#x5728;<code>.env.development</code>&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x8BBE;&#x7F6E;<code>VUE_CLI_BABEL_TRANSPILE_MODULES:true</code>&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x5177;&#x4F53;<a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/.env.development" target="_blank">&#x4EE3;&#x7801;</a>&#x3002;</p>
<p>&#x5B83;&#x7684;&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x548C;&#x539F;&#x7406;&#x4E0E;&#x4E4B;&#x524D;&#x8FD8;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x8FD8;&#x662F;&#x57FA;&#x4E8E;<code>babel-plugin-dynamic-import-node</code>&#x6765;&#x5B9E;&#x73B0;&#x7684;&#x3002;&#x4E4B;&#x6240;&#x4EE5;&#x5728;<code>vue-cli</code>&#x4E2D;&#x53EA;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x662F;&#x501F;&#x7528;&#x4E86;<code>vue-cli</code>&#x5B83;&#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#xFF0C;&#x5B83;&#x5E2E;&#x4F60;&#x4EE3;&#x7801;&#x90FD;&#x5199;&#x597D;&#x4E86;&#x3002;&#x901A;&#x8FC7;&#x9605;&#x8BFB;<a href="https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/babel-preset-app/index.js" target="_blank">&#x6E90;&#x7801;</a>&#x53EF;&#x77E5;&#xFF0C;<code>vue-cli</code>&#x4F1A;&#x901A;&#x8FC7;<code>VUE_CLI_BABEL_TRANSPILE_MODULES</code>&#x8FD9;&#x4E2A;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x6765;&#x533A;&#x5206;&#x662F;&#x5426;&#x4F7F;&#x7528;<code>babel-plugin-dynamic-import-node</code>&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EA;&#x8981;&#x5F00;&#x542F;&#x5B83;&#x5C31;&#x53EF;&#x4EE5;&#x3002;&#x867D;&#x7136;&#x5B83;&#x7684;&#x521D;&#x8877;&#x662F;&#x4E3A;&#x4E86;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x7684;&#xFF0C;&#x4F46;&#x6B63;&#x597D;&#x6EE1;&#x8DB3;&#x4E86;&#x6211;&#x4EEC;&#x7684;&#x9700;&#x6C42;&#x3002;</p>
<h3 id="&#x5E9F;&#x5F03;&#x539F;&#x56E0;">&#x5E9F;&#x5F03;&#x539F;&#x56E0;</h3>
<p>&#x5728;<code>vue-cli@3</code>&#x65F6;&#x4EE3;&#xFF0C;&#x4F7F;&#x7528;<code>VUE_CLI_BABEL_TRANSPILE_MODULES</code>&#x662F; ok &#x7684;&#xFF0C;&#x4F46;&#x5176;&#x5B9E;&#x4E5F;&#x662F;&#x8106;&#x5F31;&#x7684;&#xFF0C;&#x5C31;&#x6BD4;&#x5982;&#x5728;<code>vue-cli@4</code>&#x65F6;&#xFF0C;vue-cli &#x5F15;&#x5165;<code>babel-plugin-dynamic-import-node</code>&#x7684;&#x903B;&#x8F91;&#x5C31;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#xFF0C;&#x9700;&#x8981;<code>VUE_CLI_BABEL_TRANSPILE_MODULES</code>&#x548C;<code>VUE_CLI_BABEL_TARGET_NODE</code>&#x540C;&#x65F6;&#x4E3A; true &#x65F6;&#x624D;&#x4F1A;&#x751F;&#x6548;&#xFF0C;&#x6240;&#x4EE5;&#x53EA;&#x8981; vue-cli &#x7684;&#x5224;&#x65AD;&#x903B;&#x8F91;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#xFF0C;&#x6211;&#x4EEC;&#x90FD;&#x9700;&#x8981;&#x505A;&#x76F8;&#x5BF9;&#x5E94;&#x7684;&#x6539;&#x52A8;&#xFF0C;&#x6216;&#x975E;&#x5E38;&#x88AB;&#x52A8;&#x548C;&#x8026;&#x5408;&#x3002;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5728;<code>vue-cli@4</code>&#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x4E0D;&#x518D;&#x901A;&#x8FC7;<code>VUE_CLI_BABEL_TRANSPILE_MODULES:true</code>&#x6765;&#x8BBE;&#x7F6E;&#xFF0C;&#x800C;&#x662F;&#x901A;&#x8FC7;&#x624B;&#x52A8;&#x5F15;&#x5165;<code>&apos;babel-plugin-dynamic-import-node&apos;</code>&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5177;&#x4F53;&#x89C1;&#x4E0B;&#x4E00;&#x90E8;&#x5206;&#x3002;</p>
<h2 id="vue-cli4">vue-cli@4</h2>
<ol>
<li>&#x5728; <code>.env.development</code>&#x6587;&#x4EF6;&#x4E2D;&#x4E0D;&#x5728;&#x9700;&#x8981;&#x914D;&#x7F6E;<code>VUE_CLI_BABEL_TRANSPILE_MODULES = true</code>&#xFF0C;&#x5220;&#x9664;&#x5373;&#x53EF;&#x3002;</li>
<li>&#x5728;&#x547D;&#x4EE4;&#x884C;&#x6267;&#x884C; <code>npm install babel-plugin-dynamic-import-node -S -D</code></li>
<li>&#x5728;<code>babel.config.js</code> &#x4E2D;&#x6DFB;&#x52A0;&#x63D2;&#x4EF6;</li>
</ol>
<pre class="language-"><code class="lang-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  presets<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&apos;@vue/cli-plugin-babel/preset&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  env<span class="token operator">:</span> <span class="token punctuation">{</span>
    development<span class="token operator">:</span> <span class="token punctuation">{</span>
      plugins<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&apos;dynamic-import-node&apos;</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x6539;&#x8FDB;">&#x6539;&#x8FDB;</h2>
<p><code>webpack5</code> &#x5373;&#x5C06;&#x53D1;&#x5E03;&#xFF0C;&#x5927;&#x5E45;&#x63D0;&#x9AD8;&#x4E86;&#x6253;&#x5305;&#x548C;&#x7F16;&#x8BD1;&#x901F;&#x5EA6;&#xFF0C;&#x4E4B;&#x540E;&#x53EF;&#x80FD;&#x5B8C;&#x5168;&#x4E0D;&#x9700;&#x8981;&#x641E;&#x8FD9;&#x4E48;&#x590D;&#x6742;&#x4E86;&#xFF0C;&#x518D;&#x591A;&#x7684;&#x9875;&#x9762;&#x70ED;&#x66F4;&#x65B0;&#xFF0C;&#x90FD;&#x80FD;&#x5F88;&#x5FEB;&#xFF0C;&#x5B8C;&#x5168;&#x5C31;&#x4E0D;&#x9700;&#x8981;&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x4E86;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="cors.html" class="navigation navigation-prev " aria-label="Previous page: 跨域问题">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="icons.html" class="navigation navigation-next " aria-label="Next page: 图标">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"路由懒加载","level":"1.8","depth":1,"next":{"title":"图标","level":"1.9","depth":1,"path":"src/icons.md","ref":"src/icons.md","articles":[]},"previous":{"title":"跨域问题","level":"1.7","depth":1,"path":"src/cors.md","ref":"src/cors.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism","livereload"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"livereload":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"introduce","language":"zh-hans","gitbook":"3.2.3","description":"项目搭建、规范、使用示例介绍"},"file":{"path":"src/router-lazyload.md","mtime":"2020-07-29T03:06:30.854Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-29T07:02:36.580Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

